#include<bits/stdc++.h>
#define ll long long
// #define int ll
#define L x<<1
#define R x<<1|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define Root 1,1,n
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(ll x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=5e5+10,M=7e6+5,inf=(1LL<<31)-1,mod=998244353;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
bool S;
int n,a[N],m;
struct num{
	ll a;
	int b;//a/b
};
inline ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
inline bool cmp(num a,num b){
	return a.a*b.b<b.a*a.b;
}
inline void Max(num &a,num b){
	if(cmp(a,b))a=b;
}
num d[2005][2005];
inline void subtask1(){
	repn(i){
		int sum=0;
		rep(j,i,n){
			sum+=a[j];
			d[i][j]={1LL*sum*sum,j-i+1};
		}

	}
	int Mx=0;
	rep(len,2,n)rep(l,1,n-len+1){
		int r=l+len-1;
		Max(d[l][r],d[l][r-1]),Max(d[l][r],d[l+1][r]);
		if(len>=30)Mx=max(Mx,d[l][r].b);
	}
	repm(i){
		int l=read(),r=read();
		ll g=gcd(d[l][r].a,d[l][r].b);
		if(!d[l][r].a)puts("0 1");
		else pf(d[l][r].a/g),putchar(' '),pf(d[l][r].b/g),putchar('\n');
	}
}
int p[N],s1[N],tp1,s2[N],tp2;
inline int get(int l,int r){
	return abs(p[r]-p[l-1]);
}
num t[N];
inline void ad(int x,num k){
	x=n-x+1;
	while(x<=n)Max(t[x],k),x+=x&-x;
}
inline num query(int x){
	x=n-x+1;
	num ans={0,1};
	while(x)Max(ans,t[x]),x-=x&-x;
	return ans;
}
num out[N];
vector<Pi>q[N];
inline void subtask2(){
	repn(i)p[i]=p[i-1]+a[i],t[i]={0,1};
	repm(i){
		int l=read(),r=read();
		q[r].pb({l,i});
	}
	repn(i){
		while(tp1&&p[i-1]>=p[s1[tp1]-1])tp1--;
		s1[++tp1]=i;
		while(tp2&&p[i-1]<=p[s2[tp2]-1])tp2--;
		s2[++tp2]=i;
		int nl=tp1,nr=tp2,nw=i+1;
		num now={-1,1},fg;
		while(nl||nr){
			int x=0;
			if(!nr)x=s1[nl--];
			else if(!nl)x=s2[nr--];
			else if(s1[nl]>=s2[nr])x=s1[nl--];
			else x=s2[nr--];
			int sm=get(x,i);
			fg={1LL*sm*sm,i-x+1};
			if(!cmp(now,fg))continue;
			now=fg,nw=x;
			ad(x,fg);
			while(nl&&s1[nl]>=x)nl--;
			while(nr&&s2[nr]>=x)nr--;
		}
		for(auto y:q[i])out[y.second]=query(y.first);
	}
	repm(i){
		ll a=out[i].a,b=out[i].b,g=gcd(a,b);
		pf(a/g),putchar(' '),pf(b/g),putchar('\n');
	}
}
const int B=1500;
inline void subtask3(){
	int l=read(),r=read();
	rep(i,l,r)p[i]=p[i-1]+a[i];
	num ans={0,1};
	int Mx=0;
	rep(i,l,r){
		while(tp1&&p[i-1]>=p[s1[tp1]-1])tp1--;
		s1[++tp1]=i;
		while(tp2&&p[i-1]<=p[s2[tp2]-1])tp2--;
		s2[++tp2]=i;
		rep(j,max(1,tp1-B),tp1){
			int sm=get(s1[j],i);
			Max(ans,{1LL*sm*sm,i-s1[j]+1});
		}
		rep(j,max(1,tp2-B),tp2){
			int sm=get(s2[j],i);
			Max(ans,{1LL*sm*sm,i-s2[j]+1});
		}
	}
	ll a=ans.a,b=ans.b,g=gcd(a,b);
	pf(a/g),putchar(' '),pf(b/g),putchar('\n');
	
}
inline void Main(){
	n=read();
	repn(i)a[i]=read();
	int sum=0,Mx=0,Mn=0;
	repn(i)sum+=a[i],Mx=max(Mx,sum),Mn=min(Mn,sum);
	m=read();
	if(n==2000&&m==100000)return subtask1(),void();
	if(n==100000)return subtask2(),void();
	subtask3();
}
signed main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}